﻿package com.PlantVsZombies.util;

import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class ImageUtil {

	public static BufferedImage BACKGROUND1;
	public static BufferedImage BACKGROUND2;
	public static BufferedImage BACKGROUND3;
	public static BufferedImage bomb1;
	public static ImageIcon bomb2;

	public static BufferedImage bullet1;
	public static BufferedImage allseeds;
	public static BufferedImage allseeds_dark;
	public static BufferedImage seedbank;
	public static BufferedImage startready;
	public static BufferedImage startplant;
	public static BufferedImage startset;
	public static BufferedImage playerbullet[] = new BufferedImage[3];
	public static BufferedImage zombiebullet1;
	public static BufferedImage playerwudi;
	public static BufferedImage selectmenu;
	public static BufferedImage select[] = new BufferedImage[2];
	public static BufferedImage fanhui[] = new BufferedImage[4];

	public static BufferedImage qh1;
	public static BufferedImage qh2;
	public static BufferedImage qh3;
	
	//铁锹
	public static BufferedImage shovel;
	// 阳光
	public static ImageIcon sun;
	// 星星
	public static ImageIcon star1;
	public static ImageIcon star2;
	public static ImageIcon star3;

	// 豌豆射手
	public static ImageIcon PEAPLANT;
	public static ImageIcon PEAPLANT0;
	// 向日葵
	public static ImageIcon SUNFLOWER;
	public static ImageIcon SUNFLOWER0;
	// 樱桃植物
	public static ImageIcon CHERRY;
	// 土豆
	public static ImageIcon STONE;
	public static ImageIcon STONE1;
	public static ImageIcon STONE2;
	// 樱桃爆炸
	public static ImageIcon CHERRYBOMB;

	public static ImageIcon QH1;
	public static ImageIcon QH2;
	public static ImageIcon QH3;

	public static ImageIcon pattern2back1;
	public static ImageIcon pattern2pass;
	public static ImageIcon pattern2gameover;

	// 第二种模式僵尸
	public static ImageIcon zombies[] = new ImageIcon[7];
	public static ImageIcon boss[] = new ImageIcon[5];
	public static ImageIcon bigbullet;
	public static ImageIcon bossbullet1;
	public static ImageIcon bossbullet2;

	/**
	 * 所有僵尸
	 */
	public static boolean canMove = true;
	public static Image bucketheadZombie;
	public static Image bucketheadZombieAttack;;
	public static Image ConeheadZombie;
	public static Image ConeheadZombieAttack;;
	public static Image FlagZombie;
	public static Image FlagZombieAttack;
	public static Image FlagZombieLostHead;
	public static Image FlagZombieLostHeadAttack;;
	public static ImageIcon BoomDie;
	public static ImageIcon BoomDie1;;
	public static ImageIcon NewspaperZombie_Die;
	public static Image NewspaperZombie_Head;
	public static Image NewspaperZombieAttack_LostNewspaper;
	public static Image newspaperZombieAttack;
	public static Image newSpaperZombieAttack_LostHead;
	public static Image newSpaperZombieWalk;
	public static Image newSpaperZombieWalk_LostNewspaper;
	public static Image newSpaperZombieWalk_LostHead;
	public static Image newSpaperZombie_LostNewspaper;;
	public static Image zombie;
	public static Image zombie1;
	public static Image zombie2;
	public static Image zombieAttack;
	public static ImageIcon zombieDie;
	public static Image zombieHead;
	public static Image zombieLostHead;
	public static Image zombieAttack_LostHead;;
	public static Image FootballZombieWalk;
	public static Image FootballZombieAttack;
	public static Image FootballZombieOrnLostWalk;
	public static Image FootballZombieOrnLostAttack;
	public static Image FootballZombieLostHeadWalk;
	public static Image FootballZombieLostHeadAttack;
	public static ImageIcon FootballZombieDie;;
	public static Image PoleVaultingZombieRun;
	public static ImageIcon PoleVaultingZombieJump1;
	public static ImageIcon PoleVaultingZombieJump2;
	public static Image PoleVaultingZombieWalk;
	public static Image PoleVaultingZombieAttack;
	public static Image PoleVaultingZombieLostHeadWalk;
	public static Image PoleVaultingZombieLostHeadAttack;
	public static ImageIcon PoleVaultingZombieDie;;
	public static Image ScreenDoorZombieWalk;
	public static Image ScreenDoorZombieAttack;
	public static Image ScreenDoorZombieLostHeadWalk;
	public static Image ScreenDoorZombieLostHeadAttack;

	public static Image LoadImage(ImageIcon im) {
		Image image = null;
		Image img = null;
		img = im.getImage();
		image = Toolkit.getDefaultToolkit().createImage(img.getSource());
		return image;
	}

	static {
		try {
			BACKGROUND1 = ImageIO.read(new FileInputStream("images/interface/background1unsodded_1.jpg"));
			BACKGROUND2 = ImageIO.read(new FileInputStream("images/interface/background1.jpg"));
			BACKGROUND3 = ImageIO.read(new FileInputStream("images/interface/background2.jpg"));
			bullet1 = ImageIO.read(new FileInputStream("images/bullet_01.png"));
			allseeds = ImageIO.read(new FileInputStream("images/allseeds.png"));
			allseeds_dark = ImageIO.read(new FileInputStream("images/allseeds_dark.png"));
			seedbank = ImageIO.read(new FileInputStream("images/SeedBank.png"));
			bomb1 = ImageIO.read(new FileInputStream("images/PeaBulletHit.png"));
			startready = ImageIO.read(new FileInputStream("images/StartReady.png"));
			startset = ImageIO.read(new FileInputStream("images/StartSet.png"));
			startplant = ImageIO.read(new FileInputStream("images/StartPlant.png"));
			qh1 = ImageIO.read(new FileInputStream("images/qh1.png"));
			qh2 = ImageIO.read(new FileInputStream("images/qh2.png"));
			qh3 = ImageIO.read(new FileInputStream("images/qh3.png"));
			shovel = ImageIO.read(new FileInputStream("images/Shovel.png"));
			sun = new ImageIcon("images/Sun.gif");
			star1 = new ImageIcon("images/pattern2/Star.gif");
			star2 = new ImageIcon("images/pattern2/Starfruit.gif");
			star3 = new ImageIcon("images/pattern2/star3.png");
			playerbullet[0] = ImageIO.read(new FileInputStream("images/pattern2/playerbullet.png"));
			playerbullet[1] = ImageIO.read(new FileInputStream("images/pattern2/playerbullet2.png"));
			playerbullet[2] = ImageIO.read(new FileInputStream("images/pattern2/playerbullet3.png"));
			zombiebullet1 = ImageIO.read(new FileInputStream("images/pattern2/zombiebullet.png"));
			playerwudi = ImageIO.read(new FileInputStream("images/pattern2/playerwudi.png"));
			selectmenu = ImageIO.read(new FileInputStream("images/login/selectmenu.png"));
			for (int i = 0; i < 4; i++) {
				fanhui[i] = ImageIO.read(new FileInputStream("images/login/fanhui" + (i + 1) + ".png"));
			}
			for (int i = 0; i < 2; i++) {
				select[i] = ImageIO.read(new FileInputStream("images/login/select" + i + ".png"));
			}

			bomb2 = new ImageIcon("images/pattern2/bomb.gif");
			PEAPLANT0 = new ImageIcon("images/pattern2/player.png");
			PEAPLANT = new ImageIcon("images/image_plants/Peashooter/Peashooter.gif");
			SUNFLOWER0 = new ImageIcon("images/image_plants/SunFlower/SunFlower.gif");
			SUNFLOWER = new ImageIcon("images/image_plants/SunFlower/SunFlower.gif");
			CHERRY = new ImageIcon("images/image_plants/CherryBomb/CherryBomb.gif");
			CHERRYBOMB = new ImageIcon("images/image_plants/CherryBomb/Boom.gif");
			STONE = new ImageIcon("images/image_plants/WallNut/WallNut.gif");
			STONE1 = new ImageIcon("images/image_plants/WallNut/Wallnut_cracked1.gif");
			STONE2 = new ImageIcon("images/image_plants/WallNut/Wallnut_cracked2.gif");
			QH1 = new ImageIcon("images/QH1.gif");
			QH2 = new ImageIcon("images/QH2.gif");
			QH3 = new ImageIcon("images/QH3.gif");

			for (int i = 0; i < 3; i++) {
				zombies[i] = new ImageIcon("images/pattern2/zombie" + (i + 1) + ".gif");
			}
			zombies[3] = new ImageIcon("images/pattern2/zombie4.png");
			boss[0] = new ImageIcon("images/pattern2/boss.png");
			boss[1] = new ImageIcon("images/pattern2/boss1.png");

			pattern2back1 = new ImageIcon("images/pattern2/go.gif");
			pattern2pass = new ImageIcon("images/pattern2/pass.gif");
			pattern2gameover = new ImageIcon("images/pattern2/gameover.gif");
			bigbullet = new ImageIcon("images/pattern2/PB10.gif");
			bossbullet1 = new ImageIcon("images/pattern2/bossbullet1.gif");
			bossbullet2 = new ImageIcon("images/pattern2/bossbullet2.gif");

			bucketheadZombie = LoadImage(new ImageIcon("images/image_zombies/BucketheadZombie/BucketheadZombie.gif"));
			bucketheadZombieAttack = LoadImage(
					new ImageIcon("images/image_zombies/BucketheadZombie/BucketheadZombieAttack.gif"));

			ConeheadZombie = LoadImage(new ImageIcon("images/image_zombies/ConeheadZombie/ConeheadZombie.gif"));
			ConeheadZombieAttack = LoadImage(
					new ImageIcon("images/image_zombies/ConeheadZombie/ConeheadZombieAttack.gif"));

			FlagZombie = LoadImage(new ImageIcon("images/image_zombies/FlagZombie/FlagZombie.gif"));
			FlagZombieAttack = LoadImage(new ImageIcon("images/image_zombies/FlagZombie/FlagZombieAttack.gif"));
			FlagZombieLostHead = LoadImage(new ImageIcon("images/image_zombies/FlagZombie/FlagZombieLostHead.gif"));
			FlagZombieLostHeadAttack = LoadImage(
					new ImageIcon("images/image_zombies/FlagZombie/FlagZombieLostHeadAttack.gif"));

			BoomDie = new ImageIcon("images/image_zombies/NewspaperZombie/BoomDie.gif");
			BoomDie1 = new ImageIcon("images/image_zombies/Zombie/BoomDie.gif");

			NewspaperZombie_Die = new ImageIcon("images/image_zombies/NewspaperZombie/Die.gif");
			NewspaperZombie_Head = LoadImage(new ImageIcon("images/image_zombies/NewspaperZombie/Head.gif"));
			NewspaperZombieAttack_LostNewspaper = LoadImage(
					new ImageIcon("images/image_zombies/NewspaperZombie/HeadAttack0.gif"));
			newspaperZombieAttack = LoadImage(new ImageIcon("images/image_zombies/NewspaperZombie/HeadAttack1.gif"));
			newSpaperZombieAttack_LostHead = LoadImage(
					new ImageIcon("images/image_zombies/NewspaperZombie/LostHeadAttack0.gif"));
			newSpaperZombieWalk = LoadImage(new ImageIcon("images/image_zombies/NewspaperZombie/HeadWalk1.gif"));
			newSpaperZombieWalk_LostNewspaper = LoadImage(
					new ImageIcon("images/image_zombies/NewspaperZombie/HeadWalk0.gif"));
			newSpaperZombieWalk_LostHead = LoadImage(
					new ImageIcon("images/image_zombies/NewspaperZombie/LostHeadWalk0.gif"));
			newSpaperZombie_LostNewspaper = LoadImage(
					new ImageIcon("images/image_zombies/NewspaperZombie/LostNewspaper.gif"));

			zombie = LoadImage(new ImageIcon("images/image_zombies/Zombie/Zombie.gif"));
			zombie1 = LoadImage(new ImageIcon("images/image_zombies/Zombie/Zombie2.gif"));
			;
			zombie2 = LoadImage(new ImageIcon("images/image_zombies/Zombie/Zombie3.gif"));
			;
			zombieAttack = LoadImage(new ImageIcon("images/image_zombies/Zombie/ZombieAttack.gif"));
			;
			zombieDie = new ImageIcon("images/image_zombies/Zombie/ZombieDie.gif");
			;
			zombieHead = LoadImage(new ImageIcon("images/image_zombies/Zombie/ZombieHead.gif"));
			;
			zombieLostHead = LoadImage(new ImageIcon("images/image_zombies/Zombie/ZombieLostHead.gif"));
			;
			zombieAttack_LostHead = LoadImage(new ImageIcon("images/image_zombies/Zombie/ZombieLostHeadAttack.gif"));
			;

			FootballZombieWalk = LoadImage(new ImageIcon("images/image_zombies/FootballZombie/FootballZombie.gif"));
			FootballZombieAttack = LoadImage(new ImageIcon("images/image_zombies/FootballZombie/Attack.gif"));
			FootballZombieOrnLostWalk = LoadImage(
					new ImageIcon("images/image_zombies/FootballZombie/FootballZombieOrnLost.gif"));
			FootballZombieOrnLostAttack = LoadImage(
					new ImageIcon("images/image_zombies/FootballZombie/FootballZombieOrnLostAttack.gif"));
			FootballZombieLostHeadWalk = LoadImage(new ImageIcon("images/image_zombies/FootballZombie/LostHead.gif"));
			FootballZombieLostHeadAttack = LoadImage(
					new ImageIcon("images/image_zombies/FootballZombie/LostHeadAttack.gif"));
			FootballZombieDie = new ImageIcon("images/image_zombies/FootballZombie/Die.gif");

			PoleVaultingZombieRun = LoadImage(
					new ImageIcon("images/image_zombies/PoleVaultingZombie/PoleVaultingZombie.gif"));
			PoleVaultingZombieJump1 = new ImageIcon(
					"images/image_zombies/PoleVaultingZombie/PoleVaultingZombieJump.gif");
			PoleVaultingZombieJump2 = new ImageIcon(
					"images/image_zombies/PoleVaultingZombie/PoleVaultingZombieJump2.gif");
			PoleVaultingZombieWalk = LoadImage(
					new ImageIcon("images/image_zombies/PoleVaultingZombie/PoleVaultingZombieWalk.gif"));
			PoleVaultingZombieAttack = LoadImage(
					new ImageIcon("images/image_zombies/PoleVaultingZombie/PoleVaultingZombieAttack.gif"));
			PoleVaultingZombieLostHeadWalk = LoadImage(
					new ImageIcon("images/image_zombies/PoleVaultingZombie/PoleVaultingZombieLostHead.gif"));
			PoleVaultingZombieLostHeadAttack = LoadImage(
					new ImageIcon("images/image_zombies/PoleVaultingZombie/PoleVaultingZombieLostHeadAttack.gif"));
			PoleVaultingZombieDie = new ImageIcon("images/image_zombies/PoleVaultingZombie/PoleVaultingZombieDie.gif");

			ScreenDoorZombieWalk = LoadImage(
					new ImageIcon("images/image_zombies/ScreenDoorZombie/ScreenDoorZombie.gif"));
			ScreenDoorZombieAttack = LoadImage(
					new ImageIcon("images/image_zombies/ScreenDoorZombie/ScreenDoorZombieAttack.gif"));
			ScreenDoorZombieLostHeadWalk = LoadImage(
					new ImageIcon("images/image_zombies/ScreenDoorZombie/HeadWalk1.gif"));
			ScreenDoorZombieLostHeadAttack = LoadImage(
					new ImageIcon("images/image_zombies/ScreenDoorZombie/LostHeadAttack1.gif"));

		} catch (IOException e) {
			System.out.println("读取图片异常");
			e.printStackTrace();
		}

	}

	/**
	 * 设置透明
	 * 
	 * @param g
	 *            画笔
	 * @param alpha
	 *            透明值 0-1之间
	 */
	public static void setAlpha(Graphics g, float alpha) {
		// 源排斥目标法合成规则
		int compositeRule = AlphaComposite.SRC_OVER;
		// 创建AlphaComposite对象
		AlphaComposite alphaComposite = AlphaComposite.getInstance(compositeRule, alpha);
		// 设置图形环境的合成方式
		((Graphics2D) g).setComposite(alphaComposite);
	}
}
